package com.ayoka.ui.mine.collection;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.ayoka.R;
import com.ayoka.adapter.CourseCollectionAdapter;
import com.ayoka.base.BaseRecyclerViewFragment;
import com.ayoka.bean.CourseBean;
import com.ayoka.bean.PagerBean;
import com.ayoka.databinding.FragmentBaseRecyclerviewBinding;
import com.ayoka.mvp.CollectionMVP.CollectionPresenter;
import com.ayoka.mvp.CollectionMVP.ICollectionView;
import com.ayoka.ui.course.detail.CourseDetailActivity;
import com.jcp.baselibrary.brvah.BaseQuickAdapter;
import com.jcp.baselibrary.brvah.BaseViewHolder;

/**
 * Created by admin on 2017/3/20.
 */

public class CollectionCourseFragment extends BaseRecyclerViewFragment<CourseBean, FragmentBaseRecyclerviewBinding, CollectionPresenter> implements ICollectionView{


    public static CollectionCourseFragment newInstance() {
        CollectionCourseFragment courseCollectionFragment = new CollectionCourseFragment();
        return courseCollectionFragment;
    }

    @Override
    protected SwipeRefreshLayout getRefreshLayout() {
        return mDataBinding.swipeRefresh;
    }

    @Override
    protected RecyclerView getRecyclerView() {
        return mDataBinding.recyclerView;
    }

    @Override
    protected int getContentLayout() {
        return R.layout.fragment_base_recyclerview;
    }

    @Override
    public void initData() {
        getData(true);
    }

    @Override
    protected CollectionPresenter getPresenter() {
        return new CollectionPresenter();
    }


    @Override
    protected BaseQuickAdapter<CourseBean, BaseViewHolder> getAdapter() {
        CourseCollectionAdapter adapter = new CourseCollectionAdapter();
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                CourseBean courseBean = (CourseBean) adapter.getItem(position);
                CourseDetailActivity.start(getActivity(), courseBean.ID);
            }
        });
        return adapter;
    }

    @Override
    protected RecyclerView.ItemDecoration getRecycleDivider() {
        return null;
    }

    @Override
    protected void getData(boolean isShowWaitDialog) {
        mPresenter.getCourseCollectionListData(isShowWaitDialog, pageNo, pageSize);
    }

    @Override
    public void configCollectionListData(PagerBean data) {
        if (data == null){
            setSwipeRefreshLoadedState();
            return;
        }
        setLoadMoreLayout(data.list);
    }
}
